#include <am.h>
#include <klib.h>
#include <klib-macros.h>

#define IP_BASE_ADDR 0x10004000
#define REG_CTRL *((volatile uint32_t *)(IP_BASE_ADDR))
#define REG_PSCR *((volatile uint32_t *)(IP_BASE_ADDR + 4))
#define REG_CNT *((volatile uint32_t *)(IP_BASE_ADDR + 8))
#define REG_CMP *((volatile uint32_t *)(IP_BASE_ADDR + 12))
#define REG_CR0 *((volatile uint32_t *)(IP_BASE_ADDR + 16))
#define REG_CR1 *((volatile uint32_t *)(IP_BASE_ADDR + 20))
#define REG_CR2 *((volatile uint32_t *)(IP_BASE_ADDR + 24))
#define REG_CR3 *((volatile uint32_t *)(IP_BASE_ADDR + 28))
#define REG_STAT *((volatile uint32_t *)(IP_BASE_ADDR + 32))

int main(){
    putstr("pwm test\n");
    
    REG_CMP = (uint32_t)1000;
    REG_CR0 = (uint32_t)50;
    REG_CR1 = (uint32_t)50;

    REG_CTRL = (uint32_t)3;
    for(int i = 0; i < 3; ++i) {
        while(REG_STAT == 0);
        while(REG_STAT == 1);
    }
    printf("test done\n");
    return 0;
}
